package g2RedBlackTree;

public class MyNode<T1> {
	protected T1 sequenceNumber;    // The data in the node
	protected int color;
	protected MyNode<T1> left;       // Left child
	protected MyNode<T1> right;      // Right child
	protected MyNode<T1> parent;
	protected int levelLeft;
	protected int levelRight;
	public MyNode(){
		this(null);
	}
	public MyNode(T1 x){
		sequenceNumber  = x;
		left = null;
		right = null;
		color = 0;
		levelLeft = levelRight = 0;
		parent = null;
	}
	protected MyNode<T1> getParent(){
		return parent;
	}
	protected MyNode<T1> getGrandParent(){
		if (parent== null){
			return null;
		}
		return parent.parent;
	}
	protected MyNode<T1> getUncle(){
		MyNode<T1> g = getGrandParent();
        if (g == null)
        	return null; // No grandparent means no uncle
        if (parent == g.left)
        	return g.right;
        else
        	return g.left;
	}
	public int leftLevel(){
		return levelLeft;
	}
	public int rightLevel(){
		return levelRight;
	}
	public boolean isLeftSubTree(MyNode<T1> node){
		return left == node;
	}
	public boolean isRightSubTree(MyNode<T1> node){
		return left == node;
	}
}
